﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GTA.UserControls
{
    public partial class UcTaskHistoryReportFilter : BaseUserControl
    {
        #region Starting Control
        public UcTaskHistoryReportFilter()
        {
            InitializeComponent();
        }
        private void UcTaskHistoryReportFilter_Load(object sender, EventArgs e)
        {
            DefineDefaultDateState();
        }
        private void DefineDefaultDateState()
        {
            txtFilterEndDateFrom.Checked = false;
            txtFilterEndDateTo.Checked = false;
            txtFilterStartDateFrom.Checked = false;
            txtFilterStartDateTo.Checked = false;
        }
        #endregion

        #region Methods
        public void CleanFilter()
        {
            ucSearchFilter.CleanFilter();
            txtFilterEndDateFrom.Value = DateTime.Now;
            txtFilterEndDateFrom.Checked = false;
            txtFilterEndDateTo.Value = DateTime.Now;
            txtFilterEndDateTo.Checked = false;
            txtFilterStartDateFrom.Value = DateTime.Now;
            txtFilterStartDateFrom.Checked = false;
            txtFilterStartDateTo.Value = DateTime.Now;
            txtFilterStartDateTo.Checked = false;
        }
        public BusinessEntity.TaskHistoryFilter GetReportFilter()
        {
            return new BusinessEntity.TaskHistoryFilter()
            {
                Project = ucSearchFilter.GetSelectedProjects(),
                DesignedTo = ucSearchFilter.GetSelectedResponsiblesByID(),
                StartDateFrom = txtFilterStartDateFrom.Checked ? txtFilterStartDateFrom.Value : DateTime.MinValue,
                StartDateTo = txtFilterStartDateTo.Checked ? txtFilterStartDateTo.Value : DateTime.MinValue,
                EndDateFrom = txtFilterEndDateFrom.Checked ? txtFilterEndDateFrom.Value : DateTime.MinValue,
                EndDateTo = txtFilterEndDateTo.Checked ? txtFilterEndDateTo.Value : DateTime.MinValue
            };
        }
        internal string GetFilterDescription()
        {
            StringBuilder description = new StringBuilder();

            if (txtFilterStartDateFrom.Checked)
                description.Append("Período Data Inicial de: " + txtFilterStartDateFrom.Value.ToString(DATE_FORMAT) + "\r\n");
            if (txtFilterStartDateTo.Checked)
                description.Append("Período Data Inicial até: " + txtFilterStartDateTo.Value.ToString(DATE_FORMAT) + "\r\n");
            if (txtFilterEndDateFrom.Checked)
                description.Append("Período Data Final de: " + txtFilterEndDateFrom.Value.ToString(DATE_FORMAT) + "\r\n");
            if (txtFilterEndDateTo.Checked)
                description.Append("Período Data Final até: " + txtFilterEndDateTo.Value.ToString(DATE_FORMAT) + "\r\n");

            if (ucSearchFilter.lstProjects.CheckedItems.Count > 0)
            {
                description.Append("Projetos:");
                ucSearchFilter.GetSelectedProjects().ForEach(it => description.Append(" " + it.Name + ","));
                description.Remove(description.Length - 1, 1);
                description.Append("\r\n");
            }
            if (ucSearchFilter.lstResponsibles.CheckedItems.Count > 0)
            {
                description.Append("Responsáveis:");
                ucSearchFilter.GetSelectedResponsibles().ForEach(it => description.Append(" " + it.Name + ","));
                description.Remove(description.Length - 1, 1);
                description.Append("\r\n");
            }

            return description.ToString();
        }
        #endregion
    }
}
